<?php

namespace App\Http\Controllers\Agency;

use App\Http\Controllers\Controller;
use App\Services\MeetService;
use App\Services\MemberService;
use Illuminate\Http\Request;
use hg\apidoc\annotation as Apidoc;

/**
 * 约见工单
 * @Apidoc\Group("service")
 */
class MeetController extends Controller
{
    /**
     * @Apidoc\Title ("客户详情-更新约见状态")
     * @Apidoc\Url("/agency/meetStatusUpdate")
     * @Apidoc\Method("POST")
     * @Apidoc\Header("Authorization", type="string",require=true, desc="Bearer + accessToken")
     * @Apidoc\Param("id",type="int",require=true,desc="纸条列表id")
     * @Apidoc\Param("status",type="string",require=true,desc="wait待审核；pass通过；refuse未通过")
     * @Apidoc\Returned("true",type="bool",desc="保存状态")
     *
     */
    public function meetStatusUpdate(Request $request , MeetService $meetService)
    {
        $params = $request->input();
        $result = $meetService->updateSlipStatus($params);
        if($result)
            return $this->responseSuccess($result);
        else
            return $this->responseError(400);
    }

    /**
     * @Apidoc\Title ("约见工单列表")
     * @Apidoc\Url("/agency/meetOrderList")
     * @Apidoc\Method("POST")
     * @Apidoc\Header("Authorization", type="string",require=true, desc="Bearer + accessToken")
     * @Apidoc\Param("type",type="int",desc="1发送者id；2接收者id；3发送者昵称；4接收者昵称；5发送者手机；6接收者手机")
     * @Apidoc\Param("keyword",type="string",desc="关键字")
     * @Apidoc\Param("status",type="string",require=true,desc="wait未开始；pass已完成；refuse已取消")
     * @Apidoc\Returned("id",type="int",require=true,desc="id")
     * @Apidoc\Returned("base",type="object",require=true,desc="发起人信息")
     * @Apidoc\Returned("obase",type="object",require=true,desc="约见对象信息")
     * @Apidoc\Returned("status",type="string",require=true,desc="wait未开始；pass已完成；refuse已取消")
     * @Apidoc\Returned("option_name",type="string",require=true,desc="创建人")
     * @Apidoc\Returned("created_at",type="string",require=true,desc="申请时间")
     *
     */

    public function meetOrderList(Request $request ,MeetService $meetService)
    {
        $params = $request->input();
        $params['aid'] = $this->getAid();
        $result = $meetService->meetOrderList($params);
        return $this->responseSuccess($result);
    }

    /**
     * @Apidoc\Title ("创建服务工单-资源搜索")
     * @Apidoc\Url("/agency/searchMember")
     * @Apidoc\Method("POST")
     * @Apidoc\Header("Authorization", type="string",require=true, desc="Bearer + accessToken")
     * @Apidoc\Param("gender",type="string",require=true, desc="性别1男2女，若给男会员匹配，则传2，若给女会员匹配，则传1")
     * @Apidoc\Param("keyword",type="string",require=true, desc="关键字")
     *
     */

    public function searchMember(Request $request ,MemberService $memberService)
    {
        $params = $request->input();
        $params['aid'] = $this->getAid();
        $result = $memberService->searchMember($params);
        return $this->responseSuccess($result);
    }

    /**
     * @Apidoc\Title ("创建服务工单-扣除次数验证")
     * @Apidoc\Url("/agency/timesChecked")
     * @Apidoc\Method("POST")
     * @Apidoc\Header("Authorization", type="string",require=true, desc="Bearer + accessToken")
     * @Apidoc\Param("type",type="int",require=true,desc="1扣除发起方2双方扣除3不扣除，不扣除时不走该接口")
     * @Apidoc\Param("mid",type="int",require=true,desc="发起方客户id")
     * @Apidoc\Param("otherid",type="int",require=true,desc="被匹配方客户id")
     * @Apidoc\Returned("true",type="bool",desc="保存状态")
     *
     */
    public function timesChecked(Request $request , MemberService $memberService)
    {
        $params = $request->input();
        $params['aid'] = $this->getAid();
        $result = $memberService->timesChecked($params);
        if($result['status'])
            return $this->responseSuccess($result['data']);
        else
            return $this->responseError($result['code']);
    }

    /**
     * @Apidoc\Title ("创建服务工单")
     * @Apidoc\Url("/agency/createMeetOrder")
     * @Apidoc\Method("POST")
     * @Apidoc\Header("Authorization", type="string",require=true, desc="Bearer + accessToken")
     * @Apidoc\Param("mid",type="int",require=true,desc="约见人id")
     * @Apidoc\Param("otherid",type="int",require=true,desc="被约见人id")
     * @Apidoc\Param("type",type="int",require=true,desc="1在公司约见2在外面约见-红娘陪同3在外面约见-见面后红娘离开4自己约见")
     * @Apidoc\Param("mode",type="int",require=true,desc="1只扣约见人2扣除双方3不扣除")
     * @Apidoc\Param("meettime",type="int",require=true,desc="约见时间")
     * @Apidoc\Returned("true",type="bool",desc="保存状态")
     *
     */
    public function createMeetOrder(Request $request , MeetService $meetService)
    {
        $params = $request->input();
        $params['aid'] = $this->getAid();
        $params['uid'] = $this->getUid();
        $params['uname'] = $this->getUname();
        $result = $meetService->createMeetOrder($params);
        if($result)
            return $this->responseSuccess($result);
        else
            return $this->responseError(400);
    }
}
